_realname=maxflow
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.0.5
pkgrel=1
pkgdesc="A library implementing the max-flow/min-cut algorithm (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/gerddie/maxflow'
license=('GPL 3')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-cc")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/gerddie/${_realname}/archive/${pkgver}.tar.gz"
        "0001-fix-pc-file-escaping.patch")
sha256sums=('e73a7be173fb95e93366c8128f9f478bc2fe406f7f83eb998fc34e18eaabb612'
            'c141c2529ad3435648a1e15c55fd6f280ef47cc80957807b0eaf816632b0658b')

prepare() {
  cd ${_realname}-${pkgver}

  # https://github.com/gerddie/maxflow/pull/5
  patch -p1 -i "${srcdir}/0001-fix-pc-file-escaping.patch"
}

build() {
  cd ${srcdir}/${_realname}-${pkgver}
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && \
     rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  make DESTDIR=${pkgdir} install
}
